﻿@using VideoSeller.Business.Data.Enums
@model OnlineItemViewModel

@{
	bool iinframe = Request.QueryString.Count > 0 && Request.QueryString["fr"] != null;

	ViewBag.Title = "Online Content Details";
	if (!iinframe)
	{
		Layout = "~/Views/Shared/_DefaultLayout.cshtml";
	}
	else
	{
		Layout = "~/Views/Shared/_IFrameLayout.cshtml";
	}
    
}


@{
	var sall = "";
	var currentTab = MainTabs.Online;
	Boolean iOwner = Model.Author.UserId == Model.CurrentUserId;
	bool mHistory = Model.OnlineContentType == OnlineContentType.History;
	bool mOnline = Model.OnlineContentType == OnlineContentType.Online;
	bool mAnnounce = Model.OnlineContentType == OnlineContentType.Announcement;
	bool mFree = Model.VideoContentType == VideoContentType.Free;
	bool mPaidGroups = Model.VideoContentType == VideoContentType.PaidGroups;
	bool mPaid = Model.VideoContentType == VideoContentType.Paid;
	bool iUser = !Model.IsAnonymous;
	bool showExtVSM = false;
	bool teamCountValid = true;
	bool debug_mode = false;
	
	//
	int wtime = -1;

	Boolean useOnline =
		 mOnline || (iOwner && mAnnounce);

	if (useOnline)
	{
		currentTab = MainTabs.Online;
		mOnline = true;

	}
	else
		if (mAnnounce)
		{
			currentTab = MainTabs.Announcement;
			double waittime = (Model.BroadcastStart - DateTime.Now).TotalSeconds;
			if (waittime > 0 && waittime < 60 * 30)
			{
				wtime = Convert.ToInt32(waittime > 20 ? 20 : waittime);
			}
		}
		else if (mHistory)
		{
			currentTab = MainTabs.History;
		}

	if (mPaid && Model.TeamRemainedCount <= 0)
	{
		teamCountValid = false;
	}
	DateTime basetime = new DateTime(1970, 1, 1);
}
@if (!mHistory)
{

}
@if (!iOwner && !iinframe)
{
@Html.Partial("~/Views/Shared/_MainTabs.cshtml", currentTab)
}
<div class="tab_content"  id="content-@Model.Id">
	<div class="tab_inner tab_inner_act">
	
@if (!iinframe) {
        <div class="c_d_soc flr" style="display: inline; ">
				<!-- AddThis Button BEGIN -->
				<div class="addthis_toolbox addthis_default_style ">
					<a class="addthis_button_facebook"></a>
					<a class="addthis_button_twitter"></a>
					<a class="addthis_button_email"></a>
					<a class="addthis_button_google"></a>
					<a class="addthis_button_compact"></a>
					<a class="addthis_counter addthis_bubble_style"></a>
				</div>
				<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=xa-4ed7c5c25d51e28a"></script>
				<!-- AddThis Button END -->
			</div>
		<div style="padding: 5px;">
			<a href="javascript:history.back();">@Html.GetGlobalResource("Common", "PreviousButton")</a>
		</div>
}
		@if (Model.FilterViewModel != null && !iinframe)
  {
			@Html.Partial("~/Views/Shared/_ContentListFilter.cshtml", Model.FilterViewModel)
  }
  
		@{ViewBag.Title = Model.Title;}
        
		<div class="content_detail_block">
		
@if (!iinframe) {
			<div class="detail_header"> 
		
			
            <img src='@Url.Content(string.Format("~/content/images/video_type_{0}.png", @Model.VideoContentType.ToString()))'  class="c_d_big_field c_d_tr_type np fll"/>
			<div class="c_d_big_field c_d_name fll elipsiss">@Model.Title</div>
			<div class="c_d_big_field c_d_lang fll elipsiss" style='background-image: url(@Url.Content(Model.CultureImage)); background-position-x:2px;'>@Model.CultureCountry</div>
             
			 @if (Model.Price > 0)
			 {
				        <div class="c_d_small_field c_l_field1 fll">Price: @Html.GetCurrencyString(Model.Price)</div>
			 }
			 else
			 {
				        <div class="c_d_small_field c_d_time_from fll">@Html.GetGlobalResource("Common", "FreeContent")</div>
			 }


             <div class="c_d_small_field  fll">@Html.GetGlobalResource("Common", "StartTimeVideo"):<span id="startTimeSpanValue"> @Model.BroadcastStart.ToString("dd MMM yyyy HH:mm")</span></div>

			 

			
			<div style="clear: both;"></div>

          @*  @if (Model.FilterViewModel==null)
            {
                <div class="c_d_small_field c_l_field1 fll">@Html.GetGlobalResource("Common", "MarkedContent"):&nbsp @Model.WaitCount.ToString()</div>
            }*@
                <div class=" np fll" style="margin: 0;">
                    <table>
                         <tr>  
                            @if (mAnnounce || mOnline || mHistory)
							{
                                <td>
                                    <div class="c_d_big_field c_d_view view_icons_width">
                                        <img title='@Html.GetGlobalResource("MainTabs", "Announcement")' src='@Url.Content("~/content/images/view_a.png")' width="18" height="18" class="np"/>
										<label id="Views_anonceValue" class="Views_anonceValue">@Model.Views_anonce.ToString()</label>
                                        
                                    </div>
                                </td> 
							}
                           @if (mOnline || mHistory)
						   {
                              <td>
                                <div class="c_d_big_field c_d_view view_icons_width">
                                    <img  title='@Html.GetGlobalResource("MainTabs", "Online")'  src='@Url.Content("~/content/images/view.png")' width="18" height="18" class="np"/>
									<label id="Views_onlineValue" class="Views_onlineValue">@Model.Views_online.ToString()</label>
                                     
                                </div>
                            </td>
						   }
                            @if (mHistory)
							{
                                <td>
                                    <div class="c_d_big_field c_d_view view_icons_width">
                                        <img  title='@Html.GetGlobalResource("MainTabs", "History")'   src='@Url.Content("~/content/images/view_h.png")' width="18" height="18" class="np"/>
										<label id ="Views_historyValue" class="Views_historyValue">@Model.Views_history.ToString()</label>
                                    </div>
                                </td>
							}
                        </tr>
                    </table>
            </div>

			@if (!mAnnounce || useOnline)
   {
				        <div class="c_d_small_field  fll"><img class="moneys_img" src="/content/images/many.png" alt="paid">
							<span class="CollectedMoneyValue">
								<span id="CollectedMoneyValue">@Html.GetCurrencyString(Model.CollectedMoney)</span>
						@if (showExtVSM)
	  {
								<span id="CollectedMoneyValueExt">-@Html.GetCurrencyString(Model.CollectedMoneyExt)</span>
	  }
							
							</span>
									
				        </div>
   }

			<div class="c_d_small_field c_d_tts flr">
                @if (Model.isWaitingStart && !useOnline)
				{
					var diff = Model.BroadcastStart - DateTime.Now;
					if (diff.TotalSeconds < 0)
					{
                    <label>@Html.GetGlobalResource("Common", "WaitingContent")</label>
					}
					else
					{
                        <div id="@(string.Concat("countdown", Model.Id))"></div>
                        <script type="text/javascript">
                            var untilVal = parseInt("@diff.TotalSeconds");
                            $("#countdown" + "@Model.Id").countdown({ until: +untilVal, compact: true });
                        </script>
					}
				}

                @if (Model.Active || useOnline)
				{

					var diff = DateTime.Now;
					if (Model.Active)
					{
						diff = Model.BroadcastStart;
					}
					if (Model.Active && (DateTime.Now - diff).TotalSeconds < 8)
					{
						diff = DateTime.Now.AddSeconds(-8);
					}
                    <div id="@(string.Concat("countup", Model.Id))" class="countdown" style="color:green !important;"></div>
                    <script type="text/javascript">
                    	var needtimestart = 0;
                        var dtt = new Date(parseInt(@diff.Year), parseInt(@diff.Month-1), parseInt(@diff.Day), parseInt(@diff.Hour), parseInt(@diff.Minute), parseInt(@diff.Second), parseInt(@diff.Millisecond));
                    	
                    	$("#countup" + "@Model.Id").countdown({ since: dtt, compact: true });
                    	function pauseMyTranslateTimer() {
                    		$("#countup" + "@Model.Id").countdown('pause');
                    	}
                    	function startMyTranslateTimer() {
                    		needtimestart = 1;
                    		$("#countup" + "@Model.Id").countdown('resume');
                    	}
                    	$("#countup" + "@Model.Id").countdown('resume');
						@if (!Model.Active)
	  {		<text>      	pauseMyTranslateTimer();</text> }
                    </script>
                    <br />
				}

                	@if (mHistory)
				 {
				       <div class="hasCountdown" style="color:black;">@Model.lenHistory</div>
				 }
            </div>
                
			<div style="clear: both;"></div>
                </div>
				}
			<div id="c_d_main_img_block" class="c_d_main_img_block">
				@if (!iUser && (Model.Price > 0 || Model.UsePassword ))
	{
					<div class="registerOnlyMsg">@Html.GetGlobalResource("Common", "registerOnlyMsg")</div>
	}
				
				@if ((!mAnnounce && !iOwner && iUser) && (Model.Price > 0 && !Model.IsPaid && (Model.TeamRemainedCount > 0 || Model.TeamCount == 0)))
	{
		<div class="passwordNeedMsg">
				<label  class ="content-payment-result" id="content-payment-result" >@Html.GetGlobalResource("Flash", "PayNeedForView")</label>
				<input class="vs_btn" id="content-pay-button" type="button" data-content-id="@Model.Id" value="@Html.GetLocalResource("PayButton")" />
				<a class ="content-payment-link flr" id="content-payment-link" href="@Url.Action("Finance", "Cabinet")" >@Html.GetLocalResource("FinanceCabinet")</a>
				</div>
				<div style="clear:both;"></div>
	}

				@if (Model.UsePassword && !iOwner && (!mAnnounce || useOnline))
	{
					<div id="mainblock0">

						<div class="passwordNeedMsg">
							<span class="c_d_pass_k inline_block"></span>@Html.GetGlobalResource("Common", "passwordNeedMsg"):<input class="c_d_small_fieldf c_d_pass_t" name="meet_mypass" id="meet_mypass" type="password" />
							<button type="button" class="vs_btn" onclick= "CheckPasswordContent('@Model.Id','meet_mypass','');">@Html.GetGlobalResource("Common", "Enter")</button>
						</div>
						<div id="msg_pass" class="errPasswordMsg" style="display: none;">@Html.GetGlobalResource("Common", "errPasswordMsg")</div>

						<img alt="@Model.Description" src="@Url.GetThumbnailImage(Model.ImageUrl, ThumbnailImageSize.Large)" class="c_d_main_img_img"/>
					</div> 
	}

				@if (mAnnounce && !iOwner)
	{
					<img alt="@Model.Description" src="@Url.GetThumbnailImage(Model.ImageUrl, ThumbnailImageSize.Large)" class="c_d_main_img_img"/>
	}
				<div id="mainblock1">
					@if ((mAnnounce && iOwner) || (useOnline && !(!iUser && Model.Price > 0)))
	 {
		 if (iOwner && mAnnounce)
		 {
			 <div id="ownerPlayer" style="display:none;">
						@Html.Partial("~/Views/Shared/_OnlinePlayer.cshtml", Model)
			</div>
			<div id="ownerPreView" style="display:block;">
				<img alt="@Model.Description" src="@Url.GetThumbnailImage(Model.ImageUrl, ThumbnailImageSize.Large)" class="c_d_main_img_img"/>	
				<br />
                <button type="button" class="vs_btn" onclick="showhide('ownerPreView','none'); showhide('ownerPlayer','block'); return false; ">@Html.GetGlobalResource("Flash", "GoToPublishMainBtn")</button>
			</div>
		 }
		 else
		 {
			 			@Html.Partial("~/Views/Shared/_OnlinePlayer.cshtml", Model)
		 }
	 }
	 else
	 {
		 if (mHistory)
		 {
						@Html.Partial("~/Views/Shared/_OfflinePlayer.cshtml", Model)
		 }
	 }
				</div>
			</div>
@if (!iinframe) {			
			<div style="clear: both;"></div>


            @*CATEGORY*@
            <div id="categories_list">
                <ul>
                    @foreach (var category in Model.Categories)
					{
                        <li><h4 class="tags_category">@category.Category.Title</h4></li>
					}
                    @*HPN - вот эту конструкцию пришлось сляпать, чтобы исправить косяк предыдущего автора, по-быстрому*@
                    @if (Model.Tags.Any())
					{
						foreach (var tag in Model.Tags)
						{
							foreach (var subtag in tag.Split(',', ' ', '.'))
							{ 
                                <li><h4 class="tags">@subtag</h4></li>
							}

						}
					}
                </ul>
            </div>

			@*<div class="flr"><div class="small_link" onclick="this.className = (this.className == 'big_description' ? 'none' : 'big_description')">показать все</div></div>*@
            <div class="c_d_full_dsc big_description" onclick="this.className = (this.className == 'c_d_full_dsc big_description' ? 'c_d_full_dsc' : 'c_d_full_dsc big_description')">@Model.Description</div>    
            <div class="c_d_small_fieldf fll elipsiss" title="@Model.Author.Login"><a href="@Url.Action("Profile", "Client", new { id = Model.Author.UserId })">@Model.Author.Login</a></div>      
           @* @if (!Model.Author.sFirstName)
            {
			<div class="c_d_small_fieldf fll elipsiss" title="@Model.Author.FullName"><a href="@Url.Action("Profile", "Client", new { id = Model.Author.UserId })">@Model.Author.FullName</a></div>
            }
            else
            {
			<div class="c_d_small_fieldf fll elipsiss" title="@Model.Author.Login"><a href="@Url.Action("Profile", "Client", new { id = Model.Author.UserId })">@Model.Author.Login</a></div>
            }*@
                <div class="c_d_small_field c_l_field2 fll">
                @if (mFree)
				{
                    <span class="c_l_fields">@Model.m_AutorRating.ToString()</span>
				}

                @if (mPaid)
				{
                    <span class="c_l_fieldm">@Model.c_AutorRating.ToString()</span>
				}
			</div>

    <div class="c_d_small_fieldf fll elipsiss country_desc">@Model.country</div>
}
	@if (!iinframe && ( (mFree || mPaid) && (!mAnnounce || useOnline)))
 {
			<div class="c_d_small_fieldf c_d_like fll clickable"  onclick="if (alreadyRated==1) return false; $('#IsLike').val(true);  $('#add-new-comment').dialog('open'); ">
				<img src='@Url.Content("~/content/images/like.png")' width="18" height="18" class="np"/>
				<label id ="likeValue" class="likeValue">@Model.Likes</label>
			</div>
			<div class="c_d_small_fieldf c_d_nlike fll clickable" id=""  onclick="if (alreadyRated==1) return false; $('#IsLike').val(false);  $('#add-new-comment').dialog('open'); ">
				<img src='@Url.Content("~/content/images/unlike.png")' width="18" height="18" class="np"/>
				<label id="unlikeValue" class="unlikeValue">@Model.Unlikes</label>
			</div>
            <a class="c_d_small_fieldf fll clickable" onclick="chDisplayI('comment_block',this,'@Html.GetGlobalResource("ContentList", "HideComments")','@Html.GetGlobalResource("ContentList", "ShowComments")'); return false;">@Html.GetGlobalResource("ContentList", "ShowComments")</a>
 }
	@if (!iinframe && (Model.UsePassword && !iOwner && (!mAnnounce || useOnline)))
 {
		<div class="c_d_small_fieldf c_d_pass_k fll"></div>
                    
 }

		</div>
    @if (!iinframe &&(!mAnnounce || useOnline))
	{
	   <span class="claim-span flr">
					@if (!iOwner && iUser)
	 {
						<a class="vs_btn ClaimLink" href="javascript:void(0);" onclick=" ClaimOnlineContent('@Model.Id', '@Model.CurrentUserId'); ">@Html.GetGlobalResource("ContentList", "Claim")</a><label id="ClaimValue0" class="ClaimValue">@Model.Claims</label>
	 }
	@if (iOwner)
 {
				<span>@Html.GetGlobalResource("ContentList", "Claim"):<label id="ClaimValue"  class="ClaimValue"> @Model.Claims</label></span>
 }
	 </span>
	}
  
        		<div style="clear: both;"></div>
        	@if (!mOnline && iOwner)
		 {
				<a class="vs_btn_del flr" href="javascript:void(0);" onclick="if (this.innerHTML=='Wait...') return false; this.innerHTML='Wait...'; DeleteContent('@Model.Id');">@Html.GetGlobalResource("Common", "Delete")</a>
		 }

@*	@if (Model.Tags.Any())
  {
      foreach (var tag in Model.Tags)
      {
				<div class="tags">
					<h4>@tag&nbsp;&nbsp;</h4>
				</div>
      }
  }	*@

	<div id="mainblock2">
@if (!iinframe && (((mOnline && (mPaid || mPaidGroups) && iUser) || iOwner) && (Model.TeamDocuments != null && Model.TeamDocuments.Any())))
{
	<div class ="attachmet_block">
	    @Html.GetGlobalResource("Common", "Attachments"): 
		@if (Model.TeamDocuments != null && Model.TeamDocuments.Any())
  {
	  foreach (var file in Model.TeamDocuments)
	  {
				<a href="@Url.Content(file.Url)">@file.Name</a>
	  }
  }
	</div>
}
   @if ((!mAnnounce || useOnline) && (mFree || mPaid))
   {
	<div class="comment_block" id="comment_block" style="display:none">
		@Html.Partial("~/Views/Shared/_Comments.cshtml", Model.CommentsModel)
	</div>
   }

   @if (!mAnnounce && (mOnline && ((mPaid || mPaidGroups) && (iUser || iOwner))))
   {
	<div class="chat_block">
		@Html.Partial("~/Views/Shared/_Chat.cshtml", Model.ChatModel)
	</div>
   }
    @if (mAnnounce && iOwner && (mPaid || mPaidGroups))
	{
	<div class="chat_block" id="chat_block" style="display:none">
		@Html.Partial("~/Views/Shared/_Chat.cshtml", Model.ChatModel)
	</div>
	}

		</div>
</div>

</div>
@if(!iinframe && (mAnnounce && !iOwner))
{
	<script type="text/javascript">
	    addView('@Model.Id.ToString()', '@Model.CurrentUserId.ToString()', 'A');
	</script>
}
@if (iinframe && (mAnnounce && !iOwner))
{
	<script type="text/javascript">
		setTimeout("window.location.reload()",5000);
	</script>

}

@if (!mHistory)
{
	<script type="text/javascript">
		@if (iOwner)
  {
	 
	  <text>alreadyRated = 1;</text>
  }
		var lastStatus = '@Model.OnlineContentType.ToString()';
		@if (mOnline && iOwner)
  {
			<text>	lastStatus = 'nocheck';</text>
  }
		@if(!iinframe &&  (mOnline || iOwner))
  {
	  sall = "all";
  }

  @if (!iinframe)
	  
  {      <text>
		setTimeout("checkStat(@Model.Id,'@sall')", 5000);
		function checkStat(contentID, stats) {
			$.ajax({
				type: "POST",
				url: window.MAIN_WEB_PATH + "Ajax/isStatusChanged",
				dataType: "json",
				data: { onlineContentId: contentID, _status: stats },
				success: function (data, textStatus, jqXHR) {
				    if (data) {
				        //alert(lastStatus + "/" + data[0]);
			           if (data.length > 0) {
							if (lastStatus != 'nocheck' && data[0] != lastStatus) {
							    
								window.location.reload();
							}
							if (data.length > 11) {
								if ($("#likeValue")) $("#likeValue").text(data[2]);
								if ($("#unlikeValue")) $("#unlikeValue").text(data[3]);
								if ($("#Views_anonceValue")) $("#Views_anonceValue").text(data[4]);
								if ($("#Views_onlineValue")) $("#Views_onlineValue").text(data[5]);
								if ($("#View_currentValue")) $("#View_currentValue").text(data[6]);
								if ($("#Views_historyValue")) $("#Views_historyValue").text(data[7]);
								if ($("#CollectedMoneyValue")) $("#CollectedMoneyValue").text(data[8]);
								if ($("#CollectedMoneyValueExt")) $("#CollectedMoneyValueExt").text(data[9]);
								if (needtimestart && needtimestart == 1) {
									if ($("#startTimeSpanValue")) $("#startTimeSpanValue").text(data[10]);
									needtimestart = 0;
								}
								if ($("#ClaimValue")) $("#ClaimValue").text(data[11]);
								if ($("#ClaimValue0")) $("#ClaimValue0").text(data[11]);
								if (data[1] != ".") {
									if ($("#meet_msg")) $("#meet_msg").text(data[1]);
									if ($("#live1_msg")) $("#live1_msg").text(data[1]);

								}

								if (data[0] != "Online")
									if (pauseMyTranslateTimer)
										pauseMyTranslateTimer();
							}

	
								if (data.length > 1) {
									if (data[0] == "Online")
										if (data[1] != ".") {
											if ($("#meet_msg")) $("#meet_msg").text(data[1]);
											if ($("#live1_msg")) $("#live1_msg").text(data[1]);

										}
								}
						}
						setTimeout("checkStat(@Model.Id,'@sall')", 5000);
					}
					else
					{
						window.location.reload();
					}
				},
				error: function (data, textStatus, jqXHR) { return; }
			});
		}
		</text>
		}

  
	</script>
	
}
@if (!iinframe  && (Model.UsePassword && !iOwner))
{
	<script type="text/javascript">
		showhide('mainblock1', 'none');
		showhide('mainblock2', 'none');
	</script>
}